﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LetiLib.Data;
using LetiLib.Database;

namespace LedCenter.GUI
{
    public partial class ImageDetails : UserControl
    {
        public ImageDetails()
        {
            InitializeComponent();
            cbEffect.DataSource = Enum.GetValues(typeof(EFFECT));
            cbImageCode.DataSource = XmlDatabase.Instance.getImageTable();
            cbImageCode.DisplayMember = "ID";
            cbImageCode.ValueMember = "ID";
            cbImageCode.SelectedIndex = 0;
            btnOK.Text = "OK";
        }

        public ImageDetails(ushort playOrder)
        {
            InitializeComponent();
            cbEffect.DataSource = Enum.GetValues(typeof(EFFECT));
            cbImageCode.DataSource = XmlDatabase.Instance.getImageTable();
            cbImageCode.DisplayMember = "ID";
            cbImageCode.ValueMember = "ID";
            cbImageCode.SelectedIndex = 0;
            btnOK.Text = "OK";
            txtPlayOrder.Text = playOrder.ToString();
        }

        bool _isEdit = false;
        public bool isEdit { 
            get { return _isEdit; } 
            set { 
                _isEdit = value;
                txtPlayOrder.Enabled = cbImageCode.Enabled = nUDDelay.Enabled = cbEffect.Enabled = _isEdit;
                btnOK.Visible = _isEdit;
                btnCancel.Visible = _isEdit;
            } 
        }
        IMAGE _img;
        public IMAGE DataSource
        {
            get {
                _img.PlayOrder = byte.Parse(txtPlayOrder.Text);
                _img.ImageCode = ushort.Parse(cbImageCode.SelectedValue.ToString());
                _img.Delay = Convert.ToUInt16(nUDDelay.Value);
                _img.Effect = (EFFECT)Enum.Parse(typeof(EFFECT), cbEffect.SelectedItem.ToString());

                return _img; 
            }
            set
            {
                try
                {
                    txtPlayOrder.Text = value.PlayOrder.ToString();
                    cbImageCode.Text = value.ImageCode.ToString();
                    nUDDelay.Value = new System.Decimal(value.Delay);
                    cbEffect.SelectedItem = value.Effect;
                }
                catch (System.Exception ex)
                {
                	
                }
            }
        }

        private void ImageDetails_VisibleChanged(object sender, EventArgs e)
        {
            foreach(Control c in this.Controls)
            {
                c.Visible = this.Visible;
            }
        }
    }
}
